import { HttpErrorResponse } from "@angular/common/http";
import { Action } from "@ngrx/store";

import { LoginParams, UserToken, UserInfo } from "../../shared/modes";



export enum UserActionTypes {
    USER_LOGIN = '[User] User Login!',
    USER_LOGIN_FAIL = '[User] User Login Fail!',
    USER_LOGIN_SUCCESS = '[User] User Login Success!',

    LOAD_USER_INFO = '[User] Load User Info!',
    LOAD_USER_INFO_FAIL = '[User] Load User Info Fail!',
    LOAD_USER_INFO_SUCCESS = '[User] Load User Info Success!',

    USER_LOGOUT = '[User] User Logout!',
    USER_LOGOUT_FAIL = '[User] User Logout Fail!',
    USER_LOGOUT_SUCCESS = '[User] User Logout Success!',
}

export class UserLogin implements Action {
    readonly type = UserActionTypes.USER_LOGIN;
    constructor(public payload: LoginParams) {}
}

export class UserLoginFail implements Action {
    readonly type = UserActionTypes.USER_LOGIN_FAIL;
    constructor(public payload: HttpErrorResponse) {}
}

export class UserLoginSuccess implements Action {
    readonly type = UserActionTypes.USER_LOGIN_SUCCESS;
    constructor(public payload: UserToken) {}
}

export class LoadUserInfo implements Action {
    readonly type = UserActionTypes.LOAD_USER_INFO;
    constructor(public payload: UserToken) {}
}

export class LoadUserInfoFail implements Action {
    readonly type = UserActionTypes.LOAD_USER_INFO_FAIL;
    constructor(public payload: HttpErrorResponse) {}
}

export class LoadUserInfoSuccess implements Action {
    readonly type = UserActionTypes.LOAD_USER_INFO_SUCCESS;
    constructor(public payload: UserInfo) {}
}

export class UserLogout implements Action {
    readonly type = UserActionTypes.USER_LOGOUT;
    constructor(public payload: UserToken) {}
}

export class UserLogoutFail implements Action {
    readonly type = UserActionTypes.USER_LOGOUT_FAIL;
    constructor(public payload: HttpErrorResponse) {}
}

export class UserLogoutSuccess implements Action {
    readonly type = UserActionTypes.USER_LOGOUT_SUCCESS;
}

export type UserAction
    = UserLogin
    | UserLoginFail
    | UserLoginSuccess
    | LoadUserInfo
    | LoadUserInfoFail
    | LoadUserInfoSuccess
    | UserLogout
    | UserLogoutFail
    | UserLogoutSuccess;